<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="msg"></div>
    <input type="text" id="text">
    <input type="button" value="发送" onclick="send()">
    <script>
        var websocket = new WebSocket('ws://127.0.0.1:8080/ws')
        websocket.onopen = () => {
            console.log(websocket.readyState)
        }
        websocket.onmessage = (back) => {
            console.log(back.data)
            websocket.close()
        }
        function send() {
            var text = document.getElementById("text").value
            websocket.send(text)
        }
    </script>
</body>

</html>